package com.example.demo3.controller;



import com.example.demo3.entity.VO.Goods;
import com.example.demo3.service.IGoodsService;
import com.example.demo3.utils.PageResult;
import com.example.demo3.utils.PassToken;
import com.example.demo3.utils.ServiceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * goodssController
 * 
 * @author ruoyi
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/system/goods")
public class GoodsController
{
    @Autowired
    private IGoodsService goodsService;
    @PassToken

    /**
     * 查询goodss列表
     */
    @GetMapping("/list")
    public ServiceResponse list(Goods goods, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize)
    {
        PageResult pageResult = goodsService.selectGoodsList(goods,pageNum,pageSize);
        return ServiceResponse.createBySuccess(200,pageResult,"获取成功");
    }

    /**
     * 导出goodss列表
     */


    /**
     * 获取goodss详细信息
     */
    @GetMapping(value = "/{gid}")
    public ServiceResponse getInfo(@PathVariable("gid") Long gid)
    {
        return ServiceResponse.createBySuccess(200,goodsService.selectGoodsByGid(gid),"获取成功");
    }

    /**
     * 新增goodss
     */
    @PostMapping
    public ServiceResponse add(@RequestBody Goods goods)
    {
        int i = goodsService.insertGoods(goods);
        if(i>0){
            return ServiceResponse.createBySuccess(200,"","添加成功");
        }else{
            return  ServiceResponse.createByFail(500,"添加失败");

        }
    }

    /**
     * 修改goodss
     */
    @PutMapping
    public ServiceResponse edit(@RequestBody Goods goods)
    {
        int i = goodsService.updateGoods(goods);
        if(i>0){
            return ServiceResponse.createBySuccess(200,"","添加成功");
        }else{
            return  ServiceResponse.createByFail(500,"添加失败");

        }
    }

    /**
     * 删除goodss
     */
	@DeleteMapping("/{gids}")
    public ServiceResponse remove(@PathVariable Long[] gids)
    {
        int i = goodsService.deleteGoodsByGids(gids);
        if(i>0){
            return ServiceResponse.createBySuccess(200,"","添加成功");
        }else{
            return  ServiceResponse.createByFail(500,"添加失败");

        }
    }
    @PassToken
    @GetMapping("/frontlist")
    public ServiceResponse list1(Goods goods){
        System.out.println(goods.getCid());
        List<Goods> list = goodsService.selectGoodsListNoPage(goods);
        return ServiceResponse.createBySuccess(200,list,"获取成功");
    }
}
